package com.ma.controller;

import com.ma.dto.PostsDTO;
import com.ma.entity.Posts;
import com.ma.entity.Result;
import com.ma.service.PostsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/posts")
@Slf4j
public class PostsController {

    @Autowired
    private PostsService postsService;

    /**
     * 新增帖子
     * @param postsDTO
     * @return
     */
    @PostMapping
    public Result save(@RequestBody PostsDTO postsDTO){
        log.info("新增帖子，内容为:{}", postsDTO);
        postsService.save(postsDTO);
        return Result.success();
    }

    @GetMapping
    public Result list(){
        log.info("查询所有帖子");
        List<Posts> list = postsService.list();
        return Result.success(list);
    }
}
